package com.lj.back.manage.scaffold.common.exception;

import com.lj.back.manage.scaffold.common.enums.ResponseEnum;
import com.lj.back.manage.scaffold.common.response.Response;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 自定义异常
 * @author lv
 * @version 1.0.0
 */
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR,reason = "发生自定义异常")
public class MyException extends RuntimeException implements Response {

    /**
     * 状态码
     */
    private String code;

    /**
     * 描述信息
     */
    private String message;

    /**
     * 无参构造
     */
    public MyException(){}

    /**
     * 使用自定义异常枚举类构造自定义异常
     * @param response 统一响应枚举对象
     */
    public MyException(ResponseEnum response){
        this.code = response.getCode();
        this.message = response.getMessage();
    }

    public MyException(String code, String message){
        this.code = code;
        this.message = message;
    }


    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
